/*异步编程*/
use futures::executor;
use futures::Future;
use std::thread::sleep;
use std::time;
async fn hello(){
    println!("hello");
}

pub fn async_demo(){
    //阻塞式调用
    executor::block_on(hello());
    println!("hello world");
}

async fn learn_song(){
    println!("learn song");
    sleep(time::Duration::from_secs(5));
}

async fn sing_song(){
    println!("sing song");
}

async fn dance(){
    println!("dance");
}

async fn lean_and_sing(){
    learn_song().await; //.await会阻塞
    sing_song().await;
}

async fn async_demo2_main(){
    let f1 = lean_and_sing();
    let f2 = dance();
    futures::join!(f1, f2); //只能在async函数中执行
}

pub fn async_demo2(){
    executor::block_on(async_demo2_main());
}
